import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test01/okhttp_test/pojo/saveBasicFitnessInfo_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

import '../pages/tabbarview_test.dart';

/*
*
* 登录界面-------------锻炼次数选择
*
*
* */
class TrainPage extends StatefulWidget {
  const TrainPage({Key key}) : super(key: key);

  @override
  _TrainPageState createState() => _TrainPageState();
}

class _TrainPageState extends State<TrainPage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(
              Icons.arrow_back_ios,
              size: 28,
              color: Colors.black,
            ),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
          automaticallyImplyLeading: true,
        ),
        body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(left: 41, top: 42.5),
                child: Text(
                  "你每周训练几次",
                  style: TextStyle(
                      fontSize: 23, color: Color.fromRGBO(17, 17, 17, 1)),
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 41, top: 12),
                child: Text(
                  "我们将以此为你推荐训练计划，让你一试身手",
                  style: TextStyle(
                      fontSize: 14, color: Color.fromRGBO(51, 51, 51, 1)),
                ),
              ),
              TrainList(),
            ]));
  }
}


class TrainList extends StatefulWidget {
  const TrainList({Key key}) : super(key: key);

  @override
  _TrainListState createState() => _TrainListState();
}

///类型选择
class _TrainListState extends State<TrainList> {
  //数据被单击的下标
  int click_index;

  SaveBasicFitnessInfo _saveBasicFitnessInfo=SaveBasicFitnessInfo();

  void goalsClick(int clickindex){
    click_index=clickindex;
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      margin: EdgeInsets.only(top: 62,left: 41),
      width: MediaQuery.of(context).size.width-82,
      child:Wrap(
        //垂直布局
        direction: Axis.vertical,
        spacing: 24,
        runSpacing: 18,
        children: List.generate(3, (index) {
          return GestureDetector(


            onTap: () async{
              goalsClick(index);
              _saveBasicFitnessInfo.timesOfWeek=(click_index+3);
              bool xx=await saveBasicFitnessInfo(_saveBasicFitnessInfo,"/appuser/web/user/saveBasicFitnessInfo");
              if(xx){
                Fluttertoast.showToast(msg: "创建成功",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.BOTTOM,
                    textColor: Colors.white,
                    fontSize: 16.0
                );
                Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) {
                  return TabBarViewPage();
                }), (route) => false);
              }
            },


            child:click_index==index?
            Container(
              width: MediaQuery.of(context).size.width-82,
              height:44,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: Color.fromRGBO(17, 17, 17, 1),
                borderRadius: BorderRadius.all(Radius.circular(3.0)),
              ),
              child: Text("训练${index+3}次",style: TextStyle(fontSize: 18,color: Color.fromRGBO(255, 255, 255, 1)),),
            ):
            Container(
              width: MediaQuery.of(context).size.width-82,
              height:44,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(3.0)),
                border: Border.all(width: 1,color: Color.fromRGBO(204, 204, 204, 1).withOpacity(0.65)),
              ),

              child: Text("训练${index+3}次",style: TextStyle(fontSize: 18,color: Color.fromRGBO(17, 17, 17, 1)),),
            ),
          );
        }),
      ),
    );
  }
}
